﻿/*
--------------------------------------
File: SimpleColorDetect.cs
Project: Themaopdracht 7
Author: Maarten Kroon

Description:
A very simple color based localisation algorithm
--------------------------------------
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace THO7_Team8
{
	public class SimpleColorDetectMonogrome: ColorInterface
	{
        /// <summary>
        /// Checks for the color yellow in the image, if a yellow pixel is found we make it white, otherwise the pixel color becomes black
        /// </summary>
        /// <param name="rgbValues">a reference to the image array</param>
		public void DoAlgorithm(ref int[] rgbValues)
		{
			//Yellow color
			int margin = 100;
			int minblue = 17 - (margin / 3);
			int maxblue = 17 + (margin / 3);
			int mingreen = 204 - margin;
			int maxgreen = 204 + margin;
			int minred = 255 - margin;
			int maxred = 255 + margin;

			//Main loop which checks for yellow pixels
            for (int i = 0; i < rgbValues.Length; i++)
			{
				int blue = rgbValues[i] & 255;
				int green = (rgbValues[i] >> 8) & 255;
				int red = (rgbValues[i] >> 16) & 255;

				if(blue <= maxblue &&
					blue >= minblue &&
					green <= maxgreen &&
					green >= mingreen &&
					red <= maxred &&
					red >= minred)
				{
					//If the current pixel is yellow, copy the color from the original image into the modified array
                    rgbValues[i] = WHITE;
				}
				else
				{
					//If the current pixel is not yellow, make it black in the modified image array
                    rgbValues[i] = BLACK;
				}
			}
		}
	}
}